﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using FlyHorse.LIMS.Model;
using FlyHorse.LIMS.WinApp.LanguageResource;

namespace FlyHorse.LIMS.WinApp.OtherForms
{
    public partial class AddResultForm : DevExpress.XtraEditors.XtraForm
    {
        BLL.ToolBll toolBll = new BLL.ToolBll();
        BLL.TestItemBll testItemBll = new BLL.TestItemBll();
        Action<TestItem, string, string> _AddTestItem;
        public AddResultForm(Action<TestItem, string, string> AddTestItem)
        {
            InitializeComponent();
            _AddTestItem = AddTestItem;
        }

        private void AddResultForm_Load(object sender, EventArgs e)
        {
            List<TestItem> testItemList = toolBll.GetTestItemList();
            this.searchLookUpEdit_testItem.Properties.DataSource = testItemList;
        }



        private void simpleButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (searchLookUpEdit_testItem.EditValue == null)
                {
                    XtraMessageBox.Show(ResourceOverall.InputNull);
                    return;
                }
                string id = Convert.ToString(this.searchLookUpEdit_testItem.EditValue);
                TestItem testItem = testItemBll.LoadEntities(m => m.TestItemID == id).First();
                string minValue = "";
                string maxValue = "";
                if (this.textEdit_minValue.Text != "")
                {
                    Convert.ToDouble(this.textEdit_minValue.Text);
                    minValue = this.textEdit_minValue.Text;
                }
                if (this.textEdit_maxValue.Text != "")
                {
                    Convert.ToDouble(this.textEdit_maxValue.Text);
                    maxValue = this.textEdit_maxValue.Text;
                }
                if (!String.IsNullOrEmpty(minValue) && !String.IsNullOrEmpty(maxValue))
                {
                    if (Convert.ToDouble(minValue) > Convert.ToDouble(maxValue))
                    {
                        XtraMessageBox.Show(ResourceOverall.ValueCompareErr);
                        return;
                    }
                }
                _AddTestItem(testItem, minValue, maxValue);
                this.Close();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
      
        }
    }
}